//
//  CreateAdvertisingImageCell.swift
//  iModern
//
//  Created by Ralf on 7/29/15.
//  Copyright (c) 2015 com.starlooking. All rights reserved.
//

import UIKit

class CreateAdvertisingImageCell: TableViewCell
{
    var previewImageView:     UIImageView!
    var placeholderImageView: UIImageView!

    override func awakeFromNib()
    {
        super.awakeFromNib()

        initPreivewImageView()
        initPlaceholderImageView()
        // Initialization code
    }

    override func setSelected(selected: Bool, animated: Bool)
    {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }

    func initPreivewImageView()
    {
        if previewImageView == nil
        {
            let frame = CGRect(x: 0, y: 0, width: screen.width, height: screen.width)
            previewImageView = UIImageView(frame: frame)
            self.addSubview(previewImageView)
        }
    }

    func initPlaceholderImageView()
    {
        if placeholderImageView == nil
        {
            let frame = CGRect(x: screen.width / 4, y: screen.width / 4, width: screen.width / 2, height: screen.width / 2)
            placeholderImageView = UIImageView(frame: frame)
            placeholderImageView.image = UIImage(named: "Image")
            self.addSubview(placeholderImageView)
        }
    }

    func setData(data: NSMutableDictionary)
    {
        let image = data["image"] as? UIImage

        if image == nil
        {
            placeholderImageView.hidden = false
        }
        else
        {
            placeholderImageView.hidden = true
        }

        previewImageView.image = image
    }

    func getPreviewImageView() -> UIImageView
    {
        return previewImageView
    }
}
